package com.ma.utils;

import java.io.Serializable;

public class ResultModel<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    //code
    private Integer code;
    //msg
    private String msg;
    //data
    private  T data;

    private static final Integer CODE_SUCCESS=200;
    private static final Integer CODE_error=400;

    //成功返回
    public static <T> ResultModel<T> success(Integer code,String msg,T data){
        ResultModel<T> result = new ResultModel<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static <T> ResultModel<T> success(String msg,T data){
        ResultModel<T> result = new ResultModel<>();
        result.setCode(CODE_SUCCESS);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static <T> ResultModel<T> success(T data){
        ResultModel<T> result = new ResultModel<>();
        result.setCode(CODE_SUCCESS);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
